# coding: UTF-8
# Filename : chain_commentpost_api.py
# Company : imedia
# Author : rose
# -*-coding:utf-8 -*-
from api.common.common import *
from api.common import mysql,log,utils,httputils,const,xml_tpl, err_tpl
from django.http import HttpResponse
import chain_commentpost_data_model
import time
'''
http://api.imedia.com/app/part/list
'''
		
#details list
def chain_commentpost_list(request):
    #record log((frist action))
    httputils.footprint(request)
    #param
    cus_id = httputils.post(request, 'cus_id')#is customer id,more
    target = httputils.post(request, 'target')#is customer id,more
    target_id = httputils.post(request, 'target_id')#is customer id,more
    score = httputils.post(request, 'score')#is customer id,more
    user_id = httputils.post(request, 'user_id')#is customer id,more
    content = httputils.post(request, 'content')#is customer id,more
    size = httputils.post(request, 'size')
    pagenum = httputils.post(request, 'pagenum')
    if not utils.is_num(target): target = 1
    if not utils.is_num(user_id): user_id = 1
    if not utils.is_num(score): score = 1
    if not utils.is_num(target_id): target_id = 1
    if not utils.is_num(pagenum): pagenum = 1
    if not utils.is_num(cus_id): cus_id = 1 
    if content == '': content = '内容为空' 
    #Verification
    if validate(request):
        return validate(request)
    #models
    time_d = time.time()
    sql = '''
    insert into chain_comment (id,cus_id,target,user_id,target_id,content,score,reply_id,created_at,state)
    values
    (NULL,%s,%s,%s,%s,%s,%s,%s,%s,%s)
    '''
    param = [int(cus_id),int(target),int(user_id),int(target_id),content,score,1,time_d,0]
    mysql.insert(sql,param)
    output = ''
    output += chain_commentpost_data_model.imedia_start 
    output += chain_commentpost_data_model.imedia_body 
    output += chain_commentpost_data_model.imedia_end
    return response(output)
